﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Manage
{
    public partial class RoleManage : PageBaseBackend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindRole();
            }
        }

        //绑定角色数据
        private void bindRole()
        {
            repRole.DataSource = BLL.RoleInfoBLL.Instance.GetList();
            repRole.DataBind();
        }



        //添加角色
        protected void btnAddRole_Click(object sender, EventArgs e)
        {
            Model.RoleInfo role = new Model.RoleInfo();
            if (txtRoleName.Text.Trim() == "")
            {
                lbMessage.Text = "角色名不能为空！";
            }
            else
            {
                role.RoleName = txtRoleName.Text.Trim();
                if (BLL.RoleInfoBLL.Instance.GetDetailByRoleName(role.RoleName) != null)
                {
                    lbMessage.Text = "角色名称已存在！";
                }
                else
                {
                    role.RoleID = Guid.NewGuid().ToString();
                    role.State = (int)Common.Enum.auvState.Enabled;
                    role.IsDel = (int)Common.Enum.auvDel.NotDel;
                    role.CreateDate = DateTime.Now;
                    role.UpdateDate = DateTime.Now;
                    role.BeginDate = DateTime.Now;
                    role.EndDate = DateTime.Now;
                    BLL.RoleInfoBLL.Instance.Add(role);
                    lbMessage.Text = "添加成功！";
                    bindRole();
                }
            }
        }
    }
}